<%@ include file="../init.jsp" %>

<%@page import="java.util.Arrays"%>
<%@page import="javax.wsdl.Import"%>
<%@ page import="java.util.List" %>
<%@ page import="uit.edu.vn.portal.elearning.models.course.*" %>
<%
/**
* Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<%
	List<Site> sites = (List<Site>)request.getAttribute("sites");
	List<Site> joinable_sites = (List<Site>)request.getAttribute("joinable_sites");
	String sakaiUrl = (String)request.getAttribute("sakaiUrl");
	String userid = (String)request.getAttribute("userid");
%>

<portlet:renderURL var="editSiteURL">
	<portlet:param name="jspPage" value="/html/courseportlet/edit_course.jsp" />
	<portlet:param name="redirect" value="<%= currentURL %>" />
</portlet:renderURL>
<aui:button onClick='<%= editSiteURL %>' value='<%= "course-add-site"%>' />
					
<table>
	<tr>
		<th><liferay-ui:message key="course-title" /></th>
		<th><liferay-ui:message key="course-type" /></th>
		<th><liferay-ui:message key="course-description" /></th>
		<th><liferay-ui:message key="course-join" /></th>
	</tr>
	
<!-- Joined site -->
<%
	for(Site site:sites ){
		String linktosakai = sakaiUrl + "/portal/site/" + site.getId();
		String type = (site.getType() != null)?site.getType():""; 
		String description = (site.getDescription() != null)?site.getDescription():"";
		//if(site.getType() == null || (!site.getType().equalsIgnoreCase("course") && !site.getType().equalsIgnoreCase("project")))
			//continue;
%>
	<tr>
		<td width="35%" ><a href="<%= linktosakai %>"><%= site.getTitle() %></a></td>
		<td width="15%" ><%= type %></td>
		<td width="40%" ><%= description %></td>
		<td width="10%" ></td>
	</tr>
<% 
	} 
%>
<!-- end joined site -->

<!-- Joinable site -->
<%
	for(Site site:joinable_sites ){
		String linktosakai = sakaiUrl + "/portal/site/" + site.getId();
		String type = (site.getType() != null)?site.getType():""; 
		String description = (site.getDescription() != null)?site.getDescription():"";
		//if(site.getType() == null || (!site.getType().equalsIgnoreCase("course") && !site.getType().equalsIgnoreCase("project")))
			//continue;
%>
	<portlet:actionURL name = "JoinSite" var = "join_site_URL" >
			<portlet:param name="join_site_id" value="<%= site.getId() %>" />
			<portlet:param name="userid" value="<%= userid %>" />
	</portlet:actionURL>
	<tr>
		<td width="35%" ><%= site.getTitle() %></td>
		<td width="15%" ><%= type %></td>
		<td width="40%" ><%= description %></td>
		<td width="10%" ><a href="<%= join_site_URL %>"><liferay-ui:message key="course-join" /></a></td>
	</tr>
<% 
	} 
%>
<!-- end joinable site -->
</table>